﻿using AutoMapper;
using B.S.DataBase.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.Write.API.Appicant.Command.MeonCommand;
using MediatR;

namespace B.S.DataBase.Write.API.Appicant.CommandHandler.MeonCommandHandler
{
    /// <summary>
    /// 添加审批数据
    /// </summary>
    public class AddMeonCommandHander : IRequestHandler<AddMeonCommand, APIResult<object>>
    {

        private readonly IBaseRepository<TrunMeon> baseRepository;

        private readonly IMapper mapper;

        public AddMeonCommandHander(IBaseRepository<TrunMeon> baseRepository, IMapper mapper)
        {
            this.baseRepository = baseRepository;
            this.mapper = mapper;
        }

        public async Task<APIResult<object>> Handle(AddMeonCommand request, CancellationToken cancellationToken)
        {

            APIResult<object> result = new APIResult<object>();
            result.Code = APIEnum.添加成功;
            result.Msg =APIEnum.添加成功.ToString();


            var list = mapper.Map<TrunMeon>(request);
            list.Suesser =(int)Suess.待审核;
            list.TrunDtime =DateTime.Now;
            var res = baseRepository.Add(list).Result;



            result.data =res.ToString();

            return await Task.FromResult(result);
        }
    }
}
